<template>
    <div>
        <ul>
            <li :ref="(el) => elementArr[index] = el" v-for="(item, index) in 10" :key="index">中国{{ index }}</li>
        </ul>
    </div>
</template>

<script setup lang="ts">
import { onMounted, ref } from 'vue';
//ref第二种写法:右侧可以书写箭头函数写法,箭头函数当标签的DOM元素加载完毕会执行一次!!!
//系统会将元素DOM注入事件回调当中:elementArr[index] = el,数组每一项一次存储标签!!!!
const elementArr: any = ref([]);
onMounted(() => {
    //遍历数组
    elementArr.value.forEach((el: any) => {
        el.style.background = 'hotpink'
    })
})
</script>

<style scoped></style> 